#include <stdio.h>
#include <string.h>
#define SENTENCE_LENGTH 50
int main(void)
{
	// 定义字符数组
	char sentence[SENTENCE_LENGTH];
	int totalOfWords=0,sentence_length=0,totalOfLetters=0;
	memset(sentence,'\0',SENTENCE_LENGTH);
	printf("input a sentence:");
	fgets(sentence,SENTENCE_LENGTH,stdin);
	for(int i = 0;i < SENTENCE_LENGTH;i++)
	{
		if(sentence[i] == '\0' || sentence[i] == '\n')
		{
			totalOfWords++;
			break;
		}
		switch(sentence[i])
		{
			case ' ':
				sentence_length++;
				totalOfWords++;
				break;
			case '\n':
				break;
			default :
				totalOfLetters++;	
				sentence_length++;
				break;	
		}
	}
	printf("total of words:%d,total of letters:%d,sentence length:%d,average letters' length:%f\n",totalOfWords,totalOfLetters,sentence_length,totalOfLetters / (float)totalOfWords);
}
